package activity;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.ci_edit.EditActivity;
import com.example.administrator.ci_edit.R;

import db.DBManager;

/**
 * Created by hello world on 2017/7/13.
 */

public class PoemShowActivity extends AppCompatActivity {
    //private ImageView imageView;
    private TextView introTextView;
    private TextView nameTextView;
    private TextView enNameTextView;
    private RelativeLayout goto_1;
    private RelativeLayout goto_2;


    @Override

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_poem_show);
        //imageView=(ImageView)findViewById(R.id.image_view);

        Intent intent = getIntent();
        final int rsndm = intent.getIntExtra("extra_mengid", 0);

        goto_1 = (RelativeLayout) findViewById(R.id.goto_1);
        goto_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PoemShowActivity.this, EditActivity.class);
                intent.putExtra("extra_id", rsndm);
                startActivity(intent);
            }
        });

        goto_2 = (RelativeLayout) findViewById(R.id.goto_2);
        goto_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PoemShowActivity.this, EditActivity.class);
                intent.putExtra("extra_id", rsndm);
                startActivity(intent);
            }
        });
        //


        //font type
//        Typeface face = Typeface.createFromAsset (getAssets() , "kaiti.ttf" );
//        introTextView.setTypeface (face);
//        nameTextView.setTypeface(face);

        //数据库操作
        SQLiteDatabase db = DBManager.getNewDatabase();
        Cursor cursor = db.rawQuery("select name,source,enname from cipai where id=" + rsndm, null);


        String source = null;
        String name = null;
        String enname = null;
        while (cursor.moveToNext()) {

            source = cursor.getString(cursor.getColumnIndex("source"));
            name = cursor.getString(cursor.getColumnIndex("name"));
            enname = cursor.getString(cursor.getColumnIndex("enname"));
        }

        introTextView = (TextView) findViewById(R.id.intro_content);
        nameTextView = (TextView) findViewById(R.id.intro_name);
        enNameTextView = (TextView) findViewById(R.id.intro_enname);

        if (source != null) {
            introTextView.setText(source);
        } else introTextView.setText("             携手共进\n" +
                "ci_helper开发组要承担大量的带宽费用\n " +
                "数据库找不到也没得办法啊\n " +
                "大家可以通过打赏一起参与到ci_helper的开发中");
        //introTextView = (TextView)findViewById(R.id.intro_content);
        //introTextView.setText(source);

        nameTextView.setText(name);

        enNameTextView.setText(enname);

        //名字的导入
        //nameTextView=(TextView)findViewById(R.id.intro_name);

    }
}
